

/**************************************************************
REPLICATION CODE & DATA (1 April 2020)

Asli Cansunar. "Who is High-Income, Anyway? Social Comparison, Subjective Group Identification, and Preferences over Progressive Taxation" Journal of Politics. Forthcoming.
For questions, contact: asli.cansunar@politics.ox.ac.uk.

Filenames: 
issp2009_datacleaning.do
issp2009.R
appendix.do
ZA5400_v3-0-0.dta


**************************************************************/


*Preparing data for main analysis
clear all
set scheme s2mono

cd "/Users/aslicansunar/Dropbox/_Papers for publication/Who is High Income, Anyway?/_JOP/Final version/Replication materials"
 
use "ZA5400_v3-0-0.dta"
foreach v of varlist _all {
	local n =lower("`v'")
	rename `v' `n'
}

gen ccode=.
replace ccode=560 if v5 ==	710
replace ccode=160 if v5 ==	32
replace ccode=900 if v5 ==	36	
replace ccode=20 if v5 ==	124	
replace ccode=155 if v5 ==	152
replace ccode=713 if v5 ==	158	
replace ccode=344 if v5 ==	191	
replace ccode=316 if v5 ==	203	
replace ccode=390 if v5 ==	208	
replace ccode=375 if v5 ==	246	
replace ccode=220 if v5 ==	250	
replace ccode=310 if v5 ==	348	
replace ccode=205 if v5 ==	372	
replace ccode=666 if v5 ==	376
replace ccode=740 if v5 ==	392	
replace ccode=732 if v5 ==	410	
replace ccode=367 if v5 ==	428	
replace ccode=210 if v5 ==	528	
replace ccode=920 if v5 ==	554	
replace ccode=385 if v5 ==	578	
replace ccode=840 if v5 ==	608	
replace ccode=290 if v5 ==	616	
replace ccode=235 if v5 ==	620	
replace ccode=365 if v5 ==	643	
replace ccode=349 if v5 ==	705	
replace ccode=560 if v5 ==	710	
replace ccode=230 if v5 ==	724	
replace ccode=380 if v5 ==	752		
replace ccode=225 if v5 == 756		
replace ccode=200 if v5 ==	826	
replace ccode=2 if v5 == 840	
replace ccode=165 if v5 ==	858	
replace ccode=101 if v5 ==	862	
replace ccode=255 if v5 ==	276	
replace ccode=305 if v5 ==	40
replace ccode=211 if v5 ==	56
replace ccode=395 if v5 ==	352
replace ccode=325 if v5 ==	380
replace ccode=317 if v5 ==	703
replace ccode=640 if v5 ==	792
replace ccode=355 if v5 ==	100 
replace ccode=710 if v5 ==	156
replace ccode=353 if v5 ==	196	
replace ccode=366 if v5 ==	233	
replace ccode=369 if v5 ==	804


drop if ccode==.

kountry ccode, from(cown) to(iso3c)
rename _ISO3C_ iso3c
labmask ccode, val(iso3c)
numlabel ccode, add

decode v5, gen(C)

gen country_abb=lower(substr(C,1,2))

rename country_abb abb
levelsof abb, local(A)
foreach a of local A {
	local b=upper("`a'")
	numlabel `b'_INC, add
}

*10-Step Income Percentile adjusted by members of households 
foreach v of varlist ar_inc-za_inc{
replace `v' = `v'/sqrt(hompop)
 }
 
foreach v of varlist ar_inc-za_inc{
xtile `v'_10 = `v'  [aw=weight], n(10) 
 }

*Generate a General Household Income Decile Variable
egen income = rowmax(ar_inc_10-za_inc_10)


*Drop country if not 10 deciles
foreach v of varlist ar_inc_10-za_inc_10{
egen `v'_tag = tag(`v')
}

foreach v of varlist ar_inc_10_tag-za_inc_10_tag{
egen `v'_n = total(`v'), by(iso3c) 
}

egen ntag = rowmax(ar_inc_10_tag_n-za_inc_10_tag_n)

gen decile_10=0
replace decile_10=1 if ntag==10

drop if decile_10==0


* gender
gen female=(sex==2) if sex<.
label var female "Dummy for female"

* labor force status
gen empl_full=(wrkst==1) if wrkst<.a
label var empl_full "Dummy for full-time employed"
gen empl_part=(wrkst==2 | wrkst==3) if wrkst<.a
label var empl_part "Dummy for less than full-time employed"
gen unempl=(wrkst==5) if wrkst<.a
label var unempl "Dummy for unemployed"
gen student=(wrkst==6) if wrkst<.a
label var student "Dummy for student"
gen retired =(wrkst==7) if wrkst<.a
label var retired "Dummy for retired"
gen empl_none=(wrkst==4 | wrkst==8 | wrkst==9 | wrkst==10) if wrkst<.a
label var empl_none "Dummy for not in labor force"
gen empl_nilfs=(wrkst==4 | wrkst==6 |  wrkst==7 | wrkst==8 | wrkst==9 | wrkst==10) if wrkst<.a
label var empl_nilfs "Dummy for not in labor force"

* self-employment
gen empl_self=(wrktype==4) if wrktype<.a
label var empl_self "Dummy for self employed (many MVs!)"

* public employment
gen empl_publ=(wrktype==1 | wrktype==2) if wrktype<.a
label var empl_publ "Dummy for public employment (many MVs!)"

* TU union membership
gen tunion=(union==1 | union==2) if union<.a
label var tunion "Dummy for current or former union member (many MV!)"

* church attendance
recode attend (8=0) (7=1) (5/6=2) (4=3) (3=4) (1/2=5), gen(church)
label define church 0 "never" 5 "often", modify
numlabel church, add
label val church church
label var church "Church attendance"
* age
drop if age<22
drop if age>60
* married
gen married=0
replace married=1 if marital==1
* college
gen college=0
replace college=1 if degree==5


recode v36 (1 2 = 1) (3 4 5=0), gen(prog_2)  
recode v35 (1 2 3 = 0) (4 5=1), gen(poverty_relief)  
recode v33 (1 2 = 1) (3 4 5=0), gen(government_res)
recode v32 (1 2=1) (3 4 5=0), gen(ineq)
recode party_lr  (4 5=1) (1 2 3 6 7=0), gen(right)

*Skill specifity
merge m:m isco88 using "/Users/aslicansunar/Dropbox/_Papers for publication/Who is High Income, Anyway?/2018Spring/Replication Material/skill_specifity.dta"

*CEO - Worker distance
egen hh_income = rowmax(ar_inc-za_inc)
gen ln_dist_ceo=log(v23/hh_income)
gen ln_dist_worker=log(v25/hh_income)

****

rename age age_res
rename topbot self_placement
rename v5 code
recast long self_placement
recast long age_res
save "/Users/aslicansunar/Dropbox/_Papers for publication/Who is High Income, Anyway?/_JOP/Final version/Replication materials/issp2009.dta", replace 
keep code income female empl_part unempl retired tunion church married college prog_2 ln_dist_ceo ln_dist_worker ccode age_res self_placement college S1r party_lr v37 right
saveold "/Users/aslicansunar/Dropbox/_Papers for publication/Who is High Income, Anyway?/_JOP/Final version/Replication materials/issp2009a.dta", replace version(12)




